
<!DOCTYPE html>
  <html>
  <head>
      <meta charset="utf-8">
      <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
      <title>title</title>
      <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
            <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
      <style>
        *{margin: 0; padding: 0;font-family: "微软雅黑";}
:focus{outline: none}
input{-webkit-appearance: none;border: none;outline: none;appearance: none}
    .picpost .more{width: 100%;height: 153px;box-sizing: border-box;border: 1px solid #E8E6E6;;text-align: center;position:relative; margin-top: 20px}
    .picpost .more .btn{height: 51px;width: 78px;margin: 0 auto;margin-top:51px}
    .picpost .more .btn h5{background-color: #f8f8fa;width: 23px;height: 23px;border-radius: 50%;margin: 0 auto;text-align: center;box-sizing: border-box;background-image: url(../../image/jiahao.svg);background-repeat: no-repeat;background-position:center center;background-size: 10px 10px;border: 1px solid #}
    .picpost .more .btn p{font-size: 12px;font-weight: lighter;;color:#BFBFBF ;text-align: center;margin-top: 16px;}
    .picpost #input{width: 100%;color: #fff;text-align: center;;line-height: 38px;font-size:13px;display: block;position: fixed;bottom:20px;left: 50%;transform:translateX(-50%);}
    .picpost #input>div{margin-bottom: 1px;background-color: #999;height: 38px;}
    .picpost #input input{opacity:0;width: 100%;height: 38px;color: #fff;background-color: #999;text-align: center;;line-height: 38px;font-size:13px;display: block;position: fixed;bottom:20px;left: 50%;transform:translateX(-50%);}
      .picpost #input span{display: block;;text-align:center;line-height: 38px}
      .geshu{border: 2px solid #FFF}
      .geshu button {border: 0;background-color: transparent;outline: none;display: block;;width: 100%;font-size: 12px;height: 21px;text-align: center;;line-height: 21px;background-color: #f8f8fa;color: #999;border-radius:0;}
      .sfz{ padding-bottom:60px}
      .sfz  .title{ font-size: 14px; height: 52px; background: #FFF}
      .sfz .title  span{ display: block; float: left; width: 3px; height: 12px; background: #fc8622; line-height: 52px;margin-left: 15px; margin-right: 12px; margin-top: 20px}
      .sfz .title h3{ float: left; line-height: 52px; color: #333333;  font-size: 14px}
      .sfz button{width: 100%;background-color: #fc8622;text-align: center;;color: #FFF;border-radius: 0;margin-bottom: 20px;}
        #inpu{width: 100%;padding: 0 14px;box-sizing: border-box;}
 #inpu input{display: block;width: 100%;text-align: center;;background-color: #fc8622;line-height:40px;height:40px;box-sizing: border-box;color: #fff;font-size: 13px;margin: 30px auto;}
      .sfz img {position: absolute;width: 100%;height: 100%;left: 0;top: 0;display: block;}
      .zhengjian .con{display: flex;width: 100%;padding: 0 15px;box-sizing: border-box;justify-content:space-between;}
.zhengjian .con .col{ width: 32%}
      #fan { display: none}
      #yrz{display: none}
      #wjj{ display: none}
      </style>
  </head>
  <body>
    <section id="picpost" style="background-color:#fff">
      <div class="picpost" >
        <!-- <div class="colg"  >
        <div class="col le geshu" v-if="site.img" v-for="site in pic">
            <img v-bind:src="site.img" >

        </div>

        </div> -->


        <!-- 挖掘机信息 -->
      <div class="sfz zhengjian" id="wjj">
          <div class="title">
        <span></span>
        <h3 id="zjsc">挖掘机信息</h3>
        </div>
        <div class="con">

        <div class="col" >
          <div class="more" onclick="fnpicfile(6)">
            <img :src="z6" alt="" id="img6">
            <div class="btn" id="btn1">
              <h5></h5>
              <p>点击上传发票</p>
            </div>
          </div>
          </div>

          <div class="col" >
            <div class="more" onclick="fnpicfile(7)" >
                <img :src="z7" alt="" id="img7">
              <div class="btn" id="btn2">
                <h5></h5>
                <p>点击上传合格证</p>
              </div>
            </div>
          </div>

          <div class="col" >
            <div class="more" onclick="fnpicfile(8)" >
                <img :src="z8" alt="" id="img8">
              <div class="btn" id="btn2">
                <h5></h5>
                <p>点击上传证件</p>
              </div>
            </div>
          </div>
          </div>
      <div id="inpu" onclick="fabu()">
          <input type="submit" value="确认提交">
        </div>
    </div>


        <!-- 身份证 -->
      <div class="sfz zhengjian" id="jishizheng">
          <div class="title">
        <span></span>
        <h3 id="zjsc">证件上传</h3>
        </div>
        <div class="con">

        <div class="col" >
          <div class="more" onclick="fnpicfile(1)">
            <img :src="z1" alt="" id="img1">
            <div class="btn" id="btn1">
              <h5></h5>
              <p>点击上传</p>
            </div>
          </div>
          </div>

          <div class="col" >
            <div class="more" onclick="fnpicfile(2)" >
                <img :src="z2" alt="" id="img2">
              <div class="btn" id="btn2">
                <h5></h5>
                <p>点击上传</p>
              </div>
            </div>
          </div>

          <div class="col" >
            <div class="more" onclick="fnpicfile(3)" >
                <img :src="z3" alt="" id="img3">
              <div class="btn" id="btn2">
                <h5></h5>
                <p>点击上传</p>
              </div>
            </div>
          </div>
          </div>
          </div>
          <!-- 驾驶证 -->
          <div class="sfz" id="sfz">
              <div class="title">
            <span></span>
            <h3>身份证上传</h3>
            </div>
            <div class="con">
              <div class="col"  id="zheng">
              <div class="more" onclick="fnpicfile(4)"  >
                  <img :src="z4" alt="" id="img2">
                <div class="btn" id="btn2">
                  <h5></h5>
                  <p>点击上传证件正面</p>
                </div>
              </div>

                </div>


                <div class="col" id="fan">
                <div class="more" onclick="fnpicfile(5)" >
                    <img :src="z5" alt="" id="img2">
                  <div class="btn" id="btn2">
                    <h5></h5>
                    <p>点击上传证件反面</p>
                  </div>
                </div>
                </div>

                <div class="col" id="yrz">
                <div class="more"  >
                    <img src="../../image/renzheng.jpg"  id="img2">
                  <div class="btn" id="btn2">
                    <h5></h5>
                    <p>身份证已认证</p>
                  </div>
                </div>
                </div>


              </div>
              </div>
        <div id="input" onclick="button">
        </div>
      </div>
    </section>
  </body>
  <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/vue.min.js"></script>
  <script type="text/javascript">
  apiready = function() {
    jilu();

if($api.getStorage('shebei')=="加油"||$api.getStorage('shebei')=="拖车"){
  $api.text($api.byId("zjsc"), '照片上传');
}else{
    $api.text($api.byId("zjsc"), '证件上传');
}

    api.setRefreshHeaderInfo({
        loadingImg: 'widget://image/refresh.png',
        bgColor:  'rgba(0,0,0,0)',
        textColor: '#333',
        textDown: '下拉刷新...',
        textUp: '松开刷新...'
    }, function(ret, err) {
        jilu();


    });

    ajax();

    api.showProgress({
        style: 'default',
        animationType: 'fade',
        title: '努力加载中...',
        text: '先喝杯茶...',
        modal: false
    });

    if(api.pageParam.sftg){
      $api.css($api.byId("sfz"), 'display:none');
        $api.css($api.byId("jishizheng"), 'display:none');
        $api.css($api.byId("wjj"), 'display:block');

    api.toast({
        msg: '请上传证件后等待管理员审核',
        duration: 2000,
        location: 'bottom'
    });
    api.hideProgress();

    }
        if(api.pageParam.xiugai){
          api.toast({
              msg: '请检查修改证件',
              duration: 2000,
              location: 'bottom'
          });
        api.hideProgress();
        }

    //    console.log(JSON.stringify(api.pageParam));
pic = new Vue({
           el: '#picpost',
           data: {
              z1:"",
              z2:"",
              z3:"",
              z4:"",
              z5:"",
              z6:"",
              z7:"",
              z8:"",
           }
       });

if($api.getStorage("z1")){
  pic.z1=$api.getStorage("z1")
    api.hideProgress()
}
if($api.getStorage("z2")){
  pic.z2=$api.getStorage("z2")
    api.hideProgress()
}
if($api.getStorage("z3")){
  pic.z3=$api.getStorage("z3")
    api.hideProgress()
}


  };
    var  pic;
var z;
var orcidcard


  function fnpicfile(data){

  
    orcidcard = api.require('orcidcard');
  if(data==4){
    orcidcard.frontIdCard({
    }, function(ret, err) {
        if (ret.status) {
            if(ret.data.cardnum && ret.data.address && ret.data.name && ret.data.nation && ret.data.sex){
              shenfenzheng(ret.data,data);
            }else{
            api.toast({
                msg: '信息扫描不完整，请重新扫描',
                duration: 2000,
                location: 'bottom'
            });

          }

        } else {
            api.toast({
                msg: err.msg,
                duration: 2000,
                location: 'bottom'
            });

        }
    });
  }else if(data==5){
    orcidcard.backIdCard({
    }, function(ret, err) {
        if (ret.status) {
          console.log(ret.data.office);
          console.log(ret.data.validdate);
          if(ret.data.office && ret.data.validdate){
            shenfenzheng(ret.data,data);
          }else{
            api.toast({
                msg: '信息扫描不完整，请重新扫描',
                duration: 2000,
                location: 'bottom'
            });
          }
          //  console.log(JSON.stringify(ret.data));
        } else {
          api.toast({
              msg: err.msg,
              duration: 2000,
              location: 'bottom'
          });
        }
    });
  }else{
      api.actionSheet({
          cancelTitle: '取消 ',
          buttons: ['拍照上传','相册上传']
      }, function(ret, err){
      if(ret.buttonIndex==1){
        xiangji(data);

      }else if(ret.buttonIndex==2){
        fnpicfile1(data);
      }
      });
  }
  }


  function fnpicfile1(data){

    $api.setStorage('dd', data);
    api.getPicture({
      sourceType: 'album',
      mediaValue: 'pic',
      destinationType: 'base64',
      allowEdit: true,
      quality: 80,
      targetWidth: 800,
      targetHeight: 800,
      saveToPhotoAlbum: false
  }, function(ret, err) {
      if (ret) {
        // obj.id = Number($api.getStorage("geshu"))+1;
        if($api.getStorage("dd")==1){
            pic.z1=ret.data;
            shangchuan(ret.base64Data,$api.getStorage("dd"));
            console.log(ret)
        }
        if($api.getStorage("dd")==2){
          //console.log(22222222);
            pic.z2=ret.data;
            shangchuan(ret.base64Data,$api.getStorage("dd"));
        }
        if($api.getStorage("dd")==3){
            pic.z3=ret.data;
            shangchuan(ret.base64Data,$api.getStorage("dd"));
        }

        if($api.getStorage("dd")==6){
            pic.z6=ret.data;
            shangchuan(ret.base64Data,$api.getStorage("dd"));
        }
        if($api.getStorage("dd")==7){
            pic.z7=ret.data;
            shangchuan(ret.base64Data,$api.getStorage("dd"));
        }
        if($api.getStorage("dd")==8){
            pic.z8=ret.data;
            shangchuan(ret.base64Data,$api.getStorage("dd"));
        }
      //    console.log(JSON.stringify(ret));
      } else {
          console.log(JSON.stringify(err));
      }
  });

  }

function xiangji(data){
console.log(data);
$api.setStorage('dd', data);
  api.getPicture({
    sourceType: 'camera',
    encodingType: 'jpg',
    mediaValue: 'pic',
    destinationType: 'base64',
    allowEdit: true,
    quality: 80,
    targetWidth: 800,
    targetHeight: 800,
    saveToPhotoAlbum: false
}, function(ret, err) {
    if (ret) {
    if($api.getStorage("dd")==1){
        pic.z1=ret.data;
        shangchuan(ret.base64Data,$api.getStorage("dd"));
    }
    if($api.getStorage("dd")==2){
      //console.log(22222222);
        pic.z2=ret.data;
        shangchuan(ret.base64Data,$api.getStorage("dd"));
    }
    if($api.getStorage("dd")==3){
        pic.z3=ret.data;
        shangchuan(ret.base64Data,$api.getStorage("dd"));
    }

    if($api.getStorage("dd")==6){
        pic.z6=ret.data;
        shangchuan(ret.base64Data,$api.getStorage("dd"));
    }
    if($api.getStorage("dd")==7){
        pic.z7=ret.data;
        shangchuan(ret.base64Data,$api.getStorage("dd"));
    }
    if($api.getStorage("dd")==8){
        pic.z8=ret.data;
        shangchuan(ret.base64Data,$api.getStorage("dd"));
    }

    } else {
        console.log(JSON.stringify(err));
    }
});

}



function shangchuan(data,zs){
//  console.log(data);
//  var base64;
console.log(zs);

        api.ajax({
            url: $api.getStorage("backapi")+'/index.php?s=member&c=account&m=zhengjian&iajax=1',
            method: 'post',
            data: {
                values: {
                    uid: $api.getStorage('member'),
                    tx:data,
                    zs:zs,
                    // geshu:Number($api.getStorage("geshu"))+1,
                    time:(new Date()).getTime(),
                }
            }
        },function(ret, err){
            if (ret.status) {

       jilu()
              //cache(Number($api.getStorage("geshu"))+1,ret.status)
                // $api.setStorage("geshu",Number($api.getStorage("geshu"))+1)
              api.toast({
                  msg: '证件上传成功',
                  duration: 2000,
                  location: 'bottom'
              });



            } else {
        console.log(JSON.stringify(err));
            }
        });

}


function jilu(){


  var aj = 0,xx=0;
  api.ajax({
      url: $api.getStorage("backapi")+'/uploadfile/zhengjian/'+$api.getStorage("member")+'/1/800x800.jpeg',
      method: 'GET',
  },function(ret, err){

      if (err.statusCode=='200') {
        //console.log(11111);
          api.imageCache({
              url: $api.getStorage("backapi")+'/uploadfile/zhengjian/'+$api.getStorage("member")+'/1/800x800.jpeg?s='+new Date(),
          }, function(ret, err){
              if( ret ){
                   pic.z1=ret.url
                   $api.setStorage('z1', ret.url);
                   aj++
                   if(aj+xx>2){
                     api.hideProgress();
                     api.refreshHeaderLoadDone()
                   }
              }else{
                   //console.log( JSON.stringify( err ) );
              }
          });

      } else {
        xx++
        if(aj+xx>2){
          api.hideProgress();
          api.refreshHeaderLoadDone()
        }

      }
  });

  api.ajax({
      url: $api.getStorage("backapi")+'/uploadfile/zhengjian/'+$api.getStorage("member")+'/2/800x800.jpeg',
      method: 'GET',
  },function(ret, err){
      if (err.statusCode=='200') {
        //console.log(11111);
          api.imageCache({
              url: $api.getStorage("backapi")+'/uploadfile/zhengjian/'+$api.getStorage("member")+'/2/800x800.jpeg?s='+new Date()
          }, function(ret, err){
              if( ret ){
                   pic.z2=ret.url
                   $api.setStorage('z2', ret.url);
                   aj++
                   if(aj+xx>2){
                     api.hideProgress();
                     api.refreshHeaderLoadDone()
                   }
              }else{
                   //console.log( JSON.stringify( err ) );
              }
          });

      } else {
        xx++
        if(aj+xx>2){
          api.hideProgress();
          api.refreshHeaderLoadDone()
        }
      }
  });

  api.ajax({
      url: $api.getStorage("backapi")+'/uploadfile/zhengjian/'+$api.getStorage("member")+'/3/800x800.jpeg',
      method: 'GET',
  },function(ret, err){
      if (err.statusCode=='200') {
        //console.log(11111);
          api.imageCache({
              url:  $api.getStorage("backapi")+'/uploadfile/zhengjian/'+$api.getStorage("member")+'/3/800x800.jpeg?s='+new Date()
          }, function(ret, err){
              if( ret ){
                   pic.z3=ret.url
                   $api.setStorage('z3', ret.url);
                   aj++
                   if(aj+xx>2){
                     api.hideProgress();
                     api.refreshHeaderLoadDone()
                   }
              }else{
                   //console.log( JSON.stringify( err ) );
              }
          });

      } else {
        xx++
        if(aj+xx>2){
          api.hideProgress();
          api.refreshHeaderLoadDone()
        }
      }
  });


}



var array = [];



function shenfenzheng(ret,data){
  var base64
  api.showProgress({
      style: 'default',
      animationType: 'fade',
      title: '努力上传中...',
      text: '先喝杯茶...',
      modal: false
  });

  // console.log(JSON.stringify(ret));
   console.log(JSON.stringify(ret));
  // console.log(data);
  //图片转字符串

 var trans = api.require('trans');
 trans.decodeImgToBase64({
     imgPath:  ret.imagePath
 }, function(ret, err) {
   console.log(ret.base64Str);
     if (ret.status) {
       api.ajax({
           url: $api.getStorage("backapi")+'/index.php?s=member&c=account&m=sfz&iajax=1',
           method: 'post',
           data: {
               values: {
                   uid: $api.getStorage('member'),
                   tx:'data:image/jpeg;base64,'+ret.base64Str,
                   zs:data,
                   xinxi:ret,
                   time:(new Date()).getTime(),
               }
           }
       },function(ret, err){
       api.hideProgress();


           if (ret.status) {
             console.log(JSON.stringify(ret));
             api.toast({
                 msg: '上传成功',
                 duration: 2000,
                 location: 'bottom'
             });
     $api.css($api.byId("zheng"), 'display:none');
     $api.css($api.byId("fan"), 'display:block');

           } else {

             api.toast({
                 msg: '证件上传失败',
                 duration: 2000,
                 location: 'bottom'
             });


       console.log(JSON.stringify(err));
           }
       });
     } else {
      //   console.log(JSON.stringify(err));
     }
 });




}



function ajax(){
  api.ajax({
      url: $api.getStorage("backapi")+'/index.php?s=member&c=account&m=sfztype&uid='+$api.getStorage("member"),
      method: 'get',
  },function(ret, err){
    console.log($api.getStorage("member"));
        api.hideProgress();
      if (ret) {
        if(ret.status){
          if(ret.status.type==1){
            $api.css($api.byId("zheng"), 'display:none');
            $api.css($api.byId("fan"), 'display:block');
          }else if(ret.status.type==2){
            $api.css($api.byId("zheng"), 'display:none');
            $api.css($api.byId("yrz"), 'display:block');
          }
        }else{

        }

        console.log( JSON.stringify( ret ) );
      } else {
      //    console.log( JSON.stringify( err ) );
      }
  });

}


function fabu(){
  if($api.attr($api.byId("img6"),'src')){
  var zj6 = 'uploadfile/zhengjian/'+$api.getStorage("member")+'/6/800x800.jpeg';
  }
  if($api.attr($api.byId("img7"),'src')){
      var zj7 = 'uploadfile/zhengjian/'+$api.getStorage("member")+'/7/800x800.jpeg';
  }
  if($api.attr($api.byId("img8"),'src')){
      var zj8 = 'uploadfile/zhengjian/'+$api.getStorage("member")+'/8/800x800.jpeg';
  }
  api.ajax({
      url: $api.getStorage("backapi")+'/index.php?s=jishou&c=home&m=add_ajax',
      method: 'post',
      data: {
          values: {
              uid:$api.getStorage("member"),
              zj6: zj6,
              zj7: zj7,
              zj8: zj8,
              name:$api.getStorage("name"),
          }
      }
  },function(ret, err){
      if (ret) {
        //  console.log( JSON.stringify( ret ) );
          api.toast({
              msg: '申请成功请耐心等待',
              duration: 2000,
              location: 'bottom'
          });
          $api.setStorage('sftg',0);

          setTimeout(function(){api.closeWin()},1000);
      } else {
          console.log( JSON.stringify( err ) );
      }
  });

}

function wjj_ajax(ret,data){
  api.showProgress({
      style: 'default',
      animationType: 'fade',
      title: '努力上传中...',
      text: '先喝杯茶...',
      modal: false
  });
  //图片转字符串
  var image = new Image();
  image.src = ret.img;
  image.onload = function(){
  var base64 = getBase64Image(image);

  api.ajax({
      url: $api.getStorage("backapi")+'/index.php?s=member&c=account&m=sfz&iajax=1',
      method: 'post',
      data: {
          values: {
              uid: $api.getStorage('member'),
              tx:base64,
              zs:data,
              xinxi:ret,
              time:(new Date()).getTime(),
          }
      }
  },function(ret, err){
  api.hideProgress();

      if (ret.status) {
        api.toast({
            msg: '上传成功',
            duration: 2000,
            location: 'bottom'
        });

      } else {
        api.toast({
            msg: '证件上传失败',
            duration: 2000,
            location: 'bottom'
        });
      }
  });
  }

}


  </script>
  </html>
